<?php

namespace app\common\job;

use app\common\library\device\cabinet\Analysis;
use app\common\library\device\cabinet\Control;
use app\common\library\device\cabinet\Logic;
use app\common\model\mycurrency\AgentMoneyWithdrawal;
use app\common\model\mycurrency\DeviceInstruction;
use app\common\model\mycurrency\DeviceLattice;
use think\Db;
use think\Exception;
use think\Log;
use think\Queue;
use think\queue\Job;
use addons\mycurrency\library\WechatTransfer;

class Device {

    /**
     * 设备消息处理
     * @param Job $job
     * @param $data
     * @throws \think\exception\DbException
     */
    public function deviceMessage(Job $job, $data) {
        if ($job->attempts() > 3) {
            $job->delete();
        }
        echo "设备消息处理".date('H:i:s')."：" . json_encode($data)  . PHP_EOL;
        $message = $data['message'];
        $topic = $data['topic'];
        Logic::index($topic,$message);
        $job->delete();
    }

    /**
     * 管理员单个查询隔扣nfcId
     * @param Job $job
     * @param $data
     * @throws \think\exception\DbException
     */
    public function obtainNfcId(Job $job, $data) {
        if ($job->attempts() > 3) {
            $job->delete();
        }
        $device_id = $data['device_id'];//设备id
        $device_lattice_id = $data['device_lattice_id'];//设备隔扣id
        $device = \app\common\model\mycurrency\Device::where(['id' => $device_id])->find();
        $device_lattice = DeviceLattice::where(['id' => $device_lattice_id])->find();
        Control::sending($device->id,Analysis::CODE_BUKA,"{$device_lattice['number']}",[
            'device_lattice_id' => $device_lattice->id,//柜门id
            'control_type' => DeviceInstruction::CONTROL_TYPE_DULICHAXUN,
        ]);
        $job->delete();
    }

}